package core.logic.services;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import core.logic.dataAccess.PassagierDAO;
import core.models.dataModels.BoardingCheckModel;
import core.models.domainModel.Passagier;

public class BoardingCheckService {
	
		
		
	public static ArrayList<Passagier> getPassagiersByVluchtID(int VluchtID)
	{
		return PassagierDAO.GetPassagierByVluchtID(VluchtID);
	}
	
	public static ArrayList<String> getPassagiergegevensFromXML(String XmlLocatie) throws FileNotFoundException
	{
		
		ArrayList<String> result = new ArrayList<String>();
		
		try{
			
		
		XMLInputFactory input = XMLInputFactory.newInstance();
		FileReader file = new FileReader(XmlLocatie);
		XMLStreamReader reader = input.createXMLStreamReader(file);
		while (reader.hasNext())
		{
		int eventtype = reader.getEventType();
		switch (eventtype){
		case XMLStreamConstants.START_ELEMENT:	
			String element = reader.getLocalName();
			if (element.equals("Voornaam"))
			{
				result.add(reader.getElementText());
				reader.next();
			}
			else if (element.equals("Achternaam"))
			{
				result.add(reader.getElementText());
				reader.next();
			}
			else if (element.equals("Geboortedatum"))
			{
				result.add(reader.getElementText());
				reader.next();
			}
			else if (element.equals("VluchtNummer"))
			{
				result.add(reader.getElementText());
				reader.next();
			}
			else if (element.equals("VluchtId"))
			{
				result.add(reader.getElementText());
				reader.next();
			}
			else if (element.equals("PaspoortNummer"))
			{
				result.add(reader.getElementText());
				reader.next();
			}
			else
			{
				reader.next();
			}
			break;
			default:
			reader.next();
			break;
		 	}
		 }   
		
		}
		catch(FileNotFoundException fnfe)
		{
			throw fnfe;
		} catch (XMLStreamException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
}

